/**
 * 
 */
package controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import daos.CourseDAO;
import daos.StudentProfileDAO;
import daos.StudentProfileDAOImpl;
import daos.TimeSlotDAO;
import model.Course;
import model.StudentProfile;
import model.TimeSlot;

/** 
 * <!-- begin-UML-doc -->
 * <!-- end-UML-doc -->
 * @author JK
 * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
 */
public class ManageStudentController {
	/** 
	 * <!-- begin-UML-doc -->
	 * <!-- end-UML-doc -->
	 * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
	 */
	
	private ApplicationContext applicationContext;

	
	
	
	public StudentProfileDAO createStudentProfileDAO(){
		
		 applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath:persistenceTest/applicationContext.xml"});
			return  (StudentProfileDAO)applicationContext.getBean("studentProfileDAO");		
	}
	
	public TimeSlotDAO createTimeSlotDAO(){
		
		 applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath:persistenceTest/applicationContext.xml"});
			return  (TimeSlotDAO)applicationContext.getBean("timeSlotDAO");		
	}
	public CourseDAO createCourseDAO(){
		
		 applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath:persistenceTest/applicationContext.xml"});
			return  (CourseDAO)applicationContext.getBean("courseDAO");		
	}
	
	public void createStudentProfile(String fullName,double gpa) {
		      
		TimeSlotDAO timeSlotDAO = createTimeSlotDAO();
		StudentProfileDAO studentProfileDAO = createStudentProfileDAO();
		CourseDAO courseDAO = createCourseDAO();
		
   		StudentProfile student = new StudentProfile(fullName,gpa);
   	
   		studentProfileDAO.save(student);

	}

	/** 
	 * <!-- begin-UML-doc -->
	 * <!-- end-UML-doc -->
	 * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
	 */
	public void updateStudentProfile(int studentId,String fullName,int gpa) {
		StudentProfileDAO editStudentDAO = createStudentProfileDAO();
		StudentProfile studentToEdit= findStudent(studentId);
		studentToEdit.setFullName(fullName);
		studentToEdit.setGpa(gpa);
		editStudentDAO.save(studentToEdit);
	}

	
	public void deleteStudentProfile(int studentId) {
		StudentProfileDAO deleteStudentDAO = createStudentProfileDAO();
		StudentProfile studentToDelete= findStudent(studentId);
		deleteStudentDAO.delete(studentToDelete);
	
	}

	/*public*/private StudentProfile findStudent(/*Integer*/int studentID) {//isws einai ligo axrhsth h methodos borei na kalesthei apeftheias alla xreiazetai gia ta sequence na einai idio akrivws
		FindStudentController findStudentControl = new FindStudentController();
		return findStudentControl.findStudent(studentID);
		// begin-user-code
		// TODO Auto-generated method stub

		// end-user-code
	}
}